//
//  QRCodeViewController.m
//  Demo
//
//  Created by 董文博 on 15/2/9.
//  Copyright (c) 2015年 OA. All rights reserved.
//

#import "QRCodeViewController.h"
#import "ZBarSDK.h"

@interface QRCodeViewController ()<ZBarReaderDelegate,ZBarReaderViewDelegate>
@property(nonatomic,strong)ZBarReaderViewController *readvc;
@property (weak, nonatomic) IBOutlet UILabel *label;
@end

@implementation QRCodeViewController

-(ZBarReaderViewController *)readvc
{
    if (_readvc == nil) {
        _readvc = [[ZBarReaderViewController alloc] init];
    }
    return _readvc;
}

-(void)readerView:(ZBarReaderView *)readerView didReadSymbols:(ZBarSymbolSet *)symbols fromImage:(UIImage *)image
{
    
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self.readvc dismissViewControllerAnimated:YES completion:nil];
    ZBarSymbolSet *set = info[@"ZBarReaderControllerResults"];
    ZBarSymbol *sym;
    for (sym in set) {
        self.label.text = sym.data;
        return;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)scan:(UIButton *)sender {
    self.readvc.readerDelegate = self;
    ZBarImageScanner *scanner = self.readvc.scanner;
    
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];
    
    [self presentViewController:self.readvc animated:YES completion:^{
        
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
